class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def talk(self):
        return f'我的名字是{self.name},我今年{self.age}岁'


p1 = Person('旺财', 8)
print(p1.talk())


# 继承
class Goods:
    def __init__(self, name, price):
        self.name = name
        self.price = price


class Phone(Goods):
    def __init__(self, name, price, size, os):
        super().__init__(name, price)
        self.size = size
        self.os = os


p1 = Phone('苹果', 4999, 'iphone13', 'ios')
print(p1.size)


# 单例模式  一个类只能创建一个对象
class Singleton:
    __instance = None

    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super().__new__(cls)
        return cls.__instance


s1 = Singleton()
s2 = Singleton()
print(s1)
print(s2)  # 创建的两个实例内存地址一致

